package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysAlarm;
import com.ruoyi.system.service.ISysAlarmService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 告警Controller
 * 
 * @author ruoyi
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/system/alarm")
public class SysAlarmController extends BaseController
{
    @Autowired
    private ISysAlarmService sysAlarmService;

    /**
     * 查询告警列表
     */
    @PreAuthorize("@ss.hasPermi('alarm:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAlarm sysAlarm)
    {
        startPage();
        sysAlarm.setDeptId(getDeptId());
        List<SysAlarm> list = sysAlarmService.selectSysAlarmList(sysAlarm);
        return getDataTable(list);
    }

    /**
     * 导出告警列表
     */
    @PreAuthorize("@ss.hasPermi('alarm:alarm:export')")
    @Log(title = "告警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAlarm sysAlarm)
    {
        sysAlarm.setDeptId(getDeptId());
        List<SysAlarm> list = sysAlarmService.selectSysAlarmList(sysAlarm);
        ExcelUtil<SysAlarm> util = new ExcelUtil<SysAlarm>(SysAlarm.class);
        util.exportExcel(response, list, "告警数据");
    }

    /**
     * 获取告警详细信息
     */
    @PreAuthorize("@ss.hasPermi('alarm:alarm:query')")
    @GetMapping(value = "/{alarmId}")
    public AjaxResult getInfo(@PathVariable("alarmId") Long alarmId)
    {
        return success(sysAlarmService.selectSysAlarmByAlarmId(alarmId));
    }

    /**
     * 新增告警
     */
    @PreAuthorize("@ss.hasPermi('alarm:alarm:add')")
    @Log(title = "告警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAlarm sysAlarm)
    {
        return toAjax(sysAlarmService.insertSysAlarm(sysAlarm));
    }

    /**
     * 修改告警
     */
    @PreAuthorize("@ss.hasPermi('alarm:alarm:edit')")
    @Log(title = "告警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAlarm sysAlarm)
    {
        sysAlarm.setUpdateBy(getUsername());
        return toAjax(sysAlarmService.updateSysAlarm(sysAlarm));
    }

    /**
     * 删除告警
     */
    @PreAuthorize("@ss.hasPermi('alarm:alarm:remove')")
    @Log(title = "告警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{alarmIds}")
    public AjaxResult remove(@PathVariable Long[] alarmIds)
    {
        return toAjax(sysAlarmService.deleteSysAlarmByAlarmIds(alarmIds));
    }
}
